/*
 ============================================================================
 Name		: MyDataCenter.h
 Author	  : 
 Version	 : 1.0
 Copyright   : copyright readever.cn
 2009-2010
 Description : CMyDataCenter declaration
 ============================================================================
 */

#ifndef MYDATACENTER_H
#define MYDATACENTER_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>

#include <html\htmlcontrol.h> 
#include <html\htmlctlevent.h>
#include "hm\hm_listview.h"
#include "hm\hm_database.h"
#include "hm\MyWaitDlg.h"
#include "plugin.h"
#include "MClientObserver.h"

// CLASS DECLARATION
class CAknAppUi;
class CClientEngine;
class CDownloadEngine;
class CHtmlControl;
class CStreamAudioEngine;
class MSyDocHandler;
class CFeedbackHandler;
class c4_View;
class c4_Storage;
/**
 *  CMyDataCenter
 * 
 */
class MyDataCenter : public CBase, public MHtmlCtlEventObserver, public MClientObserver
	{
public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~MyDataCenter();

	/**
	 * Two-phased constructor.
	 */
	static MyDataCenter* NewL();

	/**
	 * Two-phased constructor.
	 */
	static MyDataCenter* NewLC();
	void TestMe();
	void RenderListItemL(CHtmlElement* aElement, TInt aIndex);
public:
	void ClientEvent(const int aClientID, const TDesC& aEventDescription);
	void ClientReceived(const int aClientID, const TDesC8& aRevData);	
	void ClientBodyReceived(const int aClientID, const TDesC8& aBodyData);	
private:

	/**
	 * Constructor for performing 1st stage construction
	 */
	MyDataCenter();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL();
	void AddHistory(const TDesC& link);
	bool GoBack();	
	void LoadBook(const TDesC& dbname);
	void OpenBook(const TDesC& dbname);
	void DownloadBook(const TDesC& dbname);	
	
	void ParsePage(const TDesC& paras);
	void PageMedia(c4_View* view, int rowid);
	void Post(const TDesC& poststr);
	void ParseRemoteFeedback(const CFeedbackHandler* feedback);
	void ParseXMLBuffer(const TDesC8& aBuffer, MSyDocHandler* aDocHandler);
	void PF_BookDesc(const TDesC& path);
	bool ProcessLink(const TDesC& path, bool addhistory = true);
public:
	void AddBookToList(const TDesC& bookfile, const TDesC& filename);	
	void PlayMp3(const TDesC& media);
    void HandleBufImageLoadEventL(CBufferedImageDecoder* aDecoder, const TDesC& aFileName);	
	void HandleHtmlCtlEventL(const THtmlCtlEvent& aEvent);
	void IssueHTTPPostL(const TDesC8& aUri, const TDesC8& aContentType, 
		const TDesC8& aBody, MClientObserver* aObserver = NULL);	
	void Init(CHtmlControl* aHtmlControl, MPluginObserver* aObserver);
	void LoadMemPage(c4_Storage* store, const TDesC& path, bool addhistory = false);
	TKeyResponse SuperHandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType );	
public:
	c4_Storage* iDBInfo;
	c4_Storage* iDBBook;
	c4_Storage* iDBTemp; //另一个临时表，空文件
	MyWaitDlg iWaitDlg; 
private:
	CDesCArrayFlat* iHistory;	
	CHtmlControl* iHtmlControl;	
	ChmListView iHmListView;
	ChmDataBase iHmDataBase;
	c4_Storage* iDBStore;
	MPluginObserver* iObserver;
	CStreamAudioEngine* iMp3Stream;
	TBuf<128> iCurrentDBFile;
	
	CClientEngine* iHttpEngine;
	CDownloadEngine* iHttpDownload;
	};

#endif // MYDATACENTER_H
